package com.iss.ljx.spring.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Locale;

public class BaseController {
    @Resource
    private MessageSource messageSource;
    public String getSuccessMsg(String i18nk,String ... args){
        HashMap<String,Object> message = new HashMap<>();
        Locale locale = LocaleContextHolder.getLocale();
        String msgStr = messageSource.getMessage(i18nk, args, locale);
        message.put("success", true);
        message.put("msg", msgStr);
        message.put("description", msgStr);
        String rst = JSON.toJSONString(message);
        return  rst;
    }
}
